import com.auctionhaus.Customer
import com.auctionhaus.Listing
import com.auctionhaus.Bid

class BootStrap {
    transient Date testFutureDate =  new Date()+4;
    transient Date testNearFutureDate =  new Date(System.currentTimeMillis()+10000);
    transient Date testYesterday =  new Date()-1;
    transient Date currentDate = new Date();
    def init = {
        def sellerList = []
        def buyerList = []
        for (c in 0..24){
            sellerList.add(new Customer(emailAddress: "seller${c}@gmail.com", password: "abcdefg", date:new Date(System.currentTimeMillis()+c)).save(flush:true))
            buyerList.add(new Customer(emailAddress: "buyer${c}@gmail.com", password: "abcdefg", date:new Date(System.currentTimeMillis()+c)).save(flush:true))

        }
        def listingList = []
        def oldListingList = []
        for (l in 0..24){
            def s = Customer.findByEmailAddress("seller${l}@gmail.com")
            println "Found ${s?.emailAddress}"
            listingList.add( new Listing(listName:"ListItem ${l}",
                                creationDate:currentDate, endDateTime:testFutureDate, startBidPrice:l, seller:s).save(flush:true) )
            oldListingList.add( new Listing(listName:"Old ListItem ${l}",
                                creationDate:testYesterday-2, endDateTime:testNearFutureDate, startBidPrice:l, seller:s).save(flush:true) )
            for (b in 0..l){
                listingList[l].addToBids(new Bid(amount:140+b, buyer:buyerList[l], date:new Date(System.currentTimeMillis()+b)))
                oldListingList[l].addToBids(new Bid(amount:20+b, buyer:buyerList[l], date:testYesterday-1))
            }
        }

        def admin = new Customer(emailAddress: "admin@admin.com", password: "password", date:new Date(System.currentTimeMillis()), adminRole:true)
        admin.save()



    }
    def destroy = {
    }
}
